<?
#display_error(1);
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
#setlocale(LC_ALL, "ru_RU.UTF-8");
#mb_regex_encoding('UTF-8');
function chg_iframe2div($matches)
{
   
$matches[1]=str_replace("'","",str_replace('"','',$matches[1]));

preg_match('|width=(\d+)|',$matches[1],$width);
preg_match('|height=(\d+)|',$matches[1],$height);
return '<div style=width:'.$width[1].'px;height:'.$height[1].'px;>Iframe was disabled in this preview</div>';
}

function chg_googlesynd2div($html)
{

   $lamda=mb_strpos($html,'pagead2.googlesyndication.com/pagead/show_ads.js');
  # die($html."<hr>") ;
  if($lamda)
  { 
    $part_before=mb_substr($html,0,$lamda-262);
     
    $part_after=mb_substr($html,$lamda+61);
    
    $part_middle=mb_substr($html,$lamda-262,323);
   
    preg_match('|google_ad_width = (\d*);|', $part_middle, $matches);
    $width=$matches[1];
    preg_match('|google_ad_height = (\d*);|', $part_middle, $matches);
    $height=$matches[1];
   
     #die($height."<hr>");
   return $part_before
           .'<div style="width:'.$width.'px!important;height:'.$height.'px!important;border:solid 1px black!important;font-size:14px!important;background-color:rgb(224, 224, 224)!important;text-align:center!important;overflow:hidden!important;"><div style=padding-top:'.intval(($height/2)-10).'px!important;line-height:18px!important;>Your current'.$width.'x'.$height.' AdSense placement</div></div>'
           .$part_after;
  }else return $html;
}
$html=  file_get_contents("http://segodnya.co.il");

#echo mb_regex_encoding();

$html=preg_replace_callback("|<iframe(.*)></iframe>|","chg_iframe2div",$html);
#print function_exists('mb_ereg_replace_callback');
 #$html=mb_ereg_replace('<script type="text/javascript">(.*)</script>','chg_googlesynd2div',$html);
$html=chg_googlesynd2div($html);

#$html=  mb_ereg_replace_callback('<script(.*)</script>','chg_googlesynd2div',$html);
 #print_r($html);
    # die('here<hr>');
/**/
echo $html;
?>